import { Component,OnInit } from '@angular/core';
import {TranslateService} from '@ngx-translate/core';
import { DefaultLanguageService } from '../services/default-language.service';
import { Router,ActivatedRoute,NavigationEnd } from '@angular/router';

@Component({
  selector: 'app-tabs',
  templateUrl: 'tabs.page.html',
  styleUrls: ['tabs.page.scss']
})
export class TabsPage implements OnInit{

  constructor(
    private translate: TranslateService,
    private defaultLanguageService:DefaultLanguageService,
    private router: Router,
    private route: ActivatedRoute
  ) {
    let defultLanguage = this.defaultLanguageService.getDefaultLanguage();
    this.translate.setDefaultLang(defultLanguage);
    this.translate.use(defultLanguage);
  }

  public showTabs:boolean = true;

  public isActive:Object = {
      'home':true,
      'myCredit':false,
      'myAccount':false
  };

  ngOnInit(): void {
    this.routerMonitor();
  }

  routerMonitor(){
    this.router.events.subscribe((event) => {    
      if (event instanceof NavigationEnd) {
        if(event.url == "/"
          || event.url == '/tabs/home'
          || event.url == '/tabs/myCredit'
          || event.url == '/tabs/myAccount'){
            this.showTabs = true;
          }else{
            this.showTabs = false;
          }
      }
    });
  }

  tabsRouter(tabName){
    for(let name in this.isActive){
      this.isActive[name] = name == tabName;
    }
    this.router.navigate(['/tabs/'+tabName]);
  }
}
